
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geocoding/geocoding.dart';
import 'package:massagist/manager/file_manager.dart';
import 'package:massagist/manager/request.dart';
import 'package:massagist/views/acctravel_item.dart';

import '../generated/l10n.dart';
import '../manager/config.dart';
import '../models/acctravel_model_entity.dart';

class AcctravelPage extends StatefulWidget {
  @override
  State<AcctravelPage> createState() => AcctravelPageState();
}

class AcctravelPageState extends State<AcctravelPage> {
  List<AcctravelModelEntity> items = [];
  bool showOpenLocal = true;
  String city = "";

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    initAcctravelValues();
    requestCity();
  }

  Future<void> initAcctravelValues() async {
    items = await Request.requestMainInfo();
    setState(() {

    });
  }

  Future<void> requestCity() async {
    List<Placemark> placemarks = await placemarkFromCoordinates(Config.lat, Config.lon);
    city = placemarks.first.locality!;

    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Stack(
          children: [
            Container(
              width: double.infinity,
              child: Image.asset( 'assets/images/banner_bg.png', fit: BoxFit.fitWidth, ),
            ),
            Container(
              child: Column(
                children: [
                  Container(
                    height: 88.sp,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Container(
                          width: 100.sp,
                          child: Row(
                            children: [
                              Container(
                                child: Image.asset( 'assets/images/localtion_icon.png', width: 14.sp, height: 14.sp,),
                              ),
                              Container(
                                padding: EdgeInsets.only(left: 2.sp),
                                child:
                                Text(city, style: const TextStyle(
                                  color: Color(0xFF110604),
                                  fontWeight: FontWeight.w500,
                                  fontSize: 13,
                                )),
                              ),
                            ],
                          ),
                          padding: EdgeInsets.only(left: 12.sp, bottom: 23.sp),
                        ),
                        Container(
                          padding: EdgeInsets.only(bottom: 10.sp),
                            child: Text(S.current.TAB_ACCTRAVEL_TEXT, style: NaviTitleStyle,)
                        ),
                        Container(
                            width: 100.sp,
                        ),
                      ],
                    ),
                  ),
                  Expanded(child: Container(
                    padding: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 2.sp),
                    child: SingleChildScrollView(
                      child: Column(
                        children: [
                          Container(
                            width: double.infinity,
                            child: Image.asset( 'assets/images/remind_bg.png', fit: BoxFit.fitWidth, ),
                          ),
                          Container(
                            margin: EdgeInsets.only(top: 12.sp),
                            child: Stack(
                              children: [
                                Container(
                                  width: double.infinity,
                                  child: Image.asset( 'assets/images/list_top_bg.png', fit: BoxFit.fitWidth, ),
                                ),
                                Container(
                                  padding: EdgeInsets.only(left: 12.sp, top: 10.sp),
                                  child:
                                  Text(S.current.ACCTRAVEL_LIST, style: const TextStyle(
                                    color: Color(0xFF333333),
                                    fontWeight: FontWeight.bold,
                                    fontSize: 15,
                                  )),
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: 34.sp),
                                  child: Column(
                                    children: items.map((element) {
                                      return AcctravelItem(model: element,);
                                    }).toList(),
                                  ),
                                )
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  ))
                ],
              ),
            ),
            showOpenLocal ? createOpenLocal() : Container()
          ],
        ),
      ),
    );
  }

  Widget createOpenLocal() {
    return Container(
      margin: EdgeInsets.only(left: 12.sp, right: 12.sp, top: 70.sp),
      padding: EdgeInsets.only(top: 8.sp, left: 8.sp),
      height: 44.sp,
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage('assets/images/local_select.png'),
        ),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            child: Text(S.current.OPEN_LOCATION_REMIND_TEXT, style: const TextStyle(
              color: Colors.white,
              fontWeight: FontWeight.w500,
              fontSize: 11,
            )),
          ),

          Row(
            children: [
              GestureDetector(
                child: Container(
                  width: 42.sp,
                  height: 20.sp,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(21.sp),
                  ),
                  child: Center(
                    child: Text(
                      S.current.OPEN_LOCATION_TEXT,
                      style: TextStyle(color: Color(0xFF00CA7E), fontSize: 10.sp),
                    ),
                  ),
                ),
                onTap: () {
                },
              ),
              GestureDetector(
                child: Container(
                  width: 21.sp, height: 21.sp,
                  child: Icon(Icons.close, color: Colors.white, size: 7.sp,),
                ),
                onTap: () {
                  showOpenLocal = false;
                  setState(() {

                  });
                },
              ),
            ],
          )
        ],
      ),
    );
}
}